package tp01;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import tp01.ui.Observador;

public class Leedor implements Runnable {

    public boolean lecturaExitosa;

    protected boolean listoPaEscuchar = false;

    public Leedor() {
    }

    public void leer() {
        
        try {
            
            synchronized (this) {

                lecturaExitosa = RequestCommand.leerTramaEntrante() != null;
                Observador.getInstance().publicar();

                Observador.getInstance().consola.append("\nRespuesta: " + lecturaExitosa);

            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(Leedor.class.getName()).log(Level.SEVERE, null, ex);
            }


        } catch (IOException ex) {
            Logger.getLogger(Leedor.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
        }

    }

    public void despertar() {
        listoPaEscuchar = true;
    }

    public void run() {
        leer();
    }

}
